#include "OMTimer.h"

OMTimer :: OMTimer(void)
{
	m_pTimer = PlatformManager::getSingleton().createTimer();
	m_pTimer->reset();
	m_TimerRate = 1.0f;
	reset();
}

OMTimer :: ~OMTimer(void)
{
	PlatformManager::getSingleton().destroyTimer(m_pTimer);
}

Real OMTimer :: getMilliseconds(void)
{
	Real const val = (m_RateChangeTime + ((m_pTimer->getMilliseconds() - m_RateChangeTime) * m_TimerRate)) - m_ResetTime;

	return m_StartTime + val;
}

Real OMTimer :: getSeconds(void)
{
	return (m_StartTime + getMilliseconds() / 1000.0f);
}

void OMTimer :: setTimerRate(Real const rate)
{
	m_RateChangeTime = m_pTimer->getMilliseconds();
	m_TimerRate = std::max(rate, 0.0f);
}

void OMTimer :: reset(void)
{
	m_RateChangeTime = m_pTimer->getMilliseconds();
	m_ResetTime = m_RateChangeTime;
	m_StartTime = 0.0f;
}

void OMTimer :: setTime(Real const val)
{
	m_StartTime = val;
}
